package lesson16;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.stream.IntStream;

public class MyLongAccumulator {

    public static void main(String[] args) throws InterruptedException {
        LongAccumulator longAccumulator = new LongAccumulator((x1, x2) -> x1 + x2, 0);
        ExecutorService executorService = Executors.newFixedThreadPool(8);
        IntStream.range(0,10).forEach(i -> executorService.submit(() -> longAccumulator.accumulate(i)));
        Thread.sleep(2000);
        System.out.println(longAccumulator.getThenReset());
    }

}
